package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: sky-take-out
 * @description:
 * @author: fmp
 * @create: 2023-04-09 15:10
 * @Version 1.0
 **/
@Slf4j
@RestController
@Api(tags = "订单管理")
@RequestMapping("/user/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @GetMapping("/historyOrders")
    @ApiOperation(value = "查询历史订单")
    public Result selectHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult  = orderService.selectHistoryOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }
    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result SubmitOrders(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO= orderService.submitOrders(ordersSubmitDTO);
        log.error("用户下单返回得知：{}",orderSubmitVO.toString());
        return Result.success(orderSubmitVO);
    }
    /**
     * 用户请求支付功能
     *
     * @param ordersPaymentDTO 用于请求支付相关信息(订单号码/付款方式)
     * @return 全局通用返回信息Bean(微信支付基础信息VO)
     */
    @ApiOperation("C端-用户请求支付功能")
    @PutMapping("/payment")
    public Result<OrderPaymentVO> pay(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("本次支付订单的提交信息 : {}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.pay(ordersPaymentDTO);
        log.info("本次支付订单的响应信息 : {}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
    //查询订单详情
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询订单详情")
    public Result getOrderDetails(@PathVariable Long id){
        OrderVO orderVO =orderService.getOrderDetails(id);
        return Result.success(orderVO);
    }
    //用户取消订单
    @PutMapping("/cancel/{orderId}")
    @ApiOperation("用户取消订单")
    public Result cancelOrder(@PathVariable Long orderId){
        orderService.cancelOrder(orderId);
        return Result.success();
    }
    //再来一单
    @PostMapping("/repetition/{orderId}")
    @ApiOperation("再来一单")
    public Result repetitionOrder(@PathVariable Long orderId){
        orderService.repetitionOrder(orderId);
        return Result.success();
    }
}
